var ImageList=[];
var ImageIDList=[];
var RootDir;

function DelImage(vKeyID)
{
	var idx= ImageIDList.indexOf(vKeyID);
	if(idx>-1)
	{
		ImageIDList=ArrayDeleteIndex(ImageIDList,idx);
		ImageList=ArrayDeleteIndex(ImageList,idx);
		RefreshImagePanel();
	}
}

function RefreshImagePanel()
{
	$('#img_div').empty();
	for(var v=0;v< ImageList.length;v++)
	{
		var vID= ImageList[v].ID;
		var vImageUrl=RootDir+ImageList[v].url;
		$('#img_div').append("<img src='"+vImageUrl +"' ><a href=javascript:DelImage('"+vID+"');>删除</a>");
	}
}

function AjaxOpenLayer(vTitle, vUrl, iWidth, iHeight) {	
	var vLength = arguments.length;
	if (vLength < 3) {
		iWidth = "60%";
		iHeight = "80%";
	}

	layer.open({
		type : 2,
		title : vTitle,
		maxmin : true, //开启最大化最小化按钮
		shadeClose : true,
		shade : 0.2,
		content : [ vUrl, 'yes' ], // iframe的url，no代表不显示滚动条
		area : [ iWidth, iHeight ],
		offset : [ '30px', '' ]
	});
}

function onAfterAddSubmit(ret) {
	//保存成功
	if (ret.Code == 1) {
		alert("数据增加保存成功！");
		return 1;
	}

	//数据保存失败！
	if (ret.Code == 0) {
		var vCtrlID = ret.ctrlID;
		var vMessage = ret.message;
		$("#" + vCtrlID).focus();
		alert(vMessage);
		return;
	}
}

function onFavSubmit(vKeyID,cUrl)
{
	$.ajax({
		type: "POST",
        url: cUrl,
		dataType : "json",
		cache : false,
		data : "res_id=" +vKeyID+ "&no-cache=" + Math.round(Math.random() * 10000),
		success : onAfterFavSubmit
	});
}

function onAfterFavSubmit(ret) {
	//收藏
	if (ret.Code == 1) {
		alert("收藏成功！");
		return 1;
	}

	//收藏失败！
	if (ret.Code == 0) {
		var vCtrlID = ret.ctrlID;
		var vMessage = ret.message;
		$("#" + vCtrlID).focus();
		alert(vMessage);
		return;
	}
}

function onAfterEditSubmit(ret) {
	//保存成功
	if (ret.Code == 1) {
		alert("数据修改保存成功！");
		return 1;
	}

	//数据保存失败！
	if (ret.Code == 0) {
		var vCtrlID = ret.ctrlID;
		var vMessage = ret.message;
		$("#" + vCtrlID).focus();
		alert(vMessage);
		return;
	}
}

function onAfterDelSubmit(ret) {
	//保存成功
	if (ret.Code == 1) {
		alert("数据删除成功！");
		return 1;
	}

	//数据删除失败！
	if (ret.Code == 0) {
		var vCtrlID = ret.ctrlID;
		var vMessage = ret.message;
		$("#" + vCtrlID).focus();
		alert(vMessage);
		return;
	}
}

function ArrayDeleteIndex(vArr,vIdx)
{
	var vList=[];
	for(var i=0;i<vArr.length;i++)
	{
		if(i!=vIdx)
		{
			vList.push(vArr[i]);
		}
	}
	return vList;	
}

function AutoFit() 
{   
	var ifm= document.getElementById("rf");   
	var subWeb = document.frames ? document.frames["rf"].document : ifm.contentDocument;   
	if(ifm != null && subWeb != null) 
	{
		ifm.height = subWeb.body.scrollHeight;
		ifm.width = subWeb.body.scrollWidth;
	}   
}